//
// Created by 31897 on 2021/11/2.
//

#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
const int maxn=50;
int result[maxn][maxn][3]={0};
int main()
{
    ios::sync_with_stdio(false);
    int len;
    string str;
    cin>>str;
    len=str.size();
    for (int i = 1; i <= len; i++)
    {
        if(str[i-1]=='a') result[i][i][0]=1;
        else result[i][i][0]=0;
        if(str[i-1]=='b') result[i][i][1]=1;
        else result[i][i][1]=0;
        if(str[i-1]=='c') result[i][i][2]=1;
        else result[i][i][2]=0;
    }
    for (int r = 2; r <= len; r++)
    {
        for (int i = 1; i <= len-r+1; i++)
        {
            int j = i + r - 1;
            for (int k = i; k <= j; k++)
            {
                result[i][j][0] += result[i][k][0] * result[k + 1][j][2] + result[i][k][1] * result[k + 1][j][2] + result[i][k][2] * result[k + 1][j][0];
                result[i][j][1] += result[i][k][0] * result[k + 1][j][0] + result[i][k][0] * result[k + 1][j][1] + result[i][k][1] * result[k + 1][j][1];
                result[i][j][2] += result[i][k][1] * result[k + 1][j][0] + result[i][k][2] * result[k + 1][j][1] + result[i][k][2] * result[k + 1][j][2];
            }
        }
    }
    cout << result[1][len][0] << endl;
    return 0;
}